<%
	curSchoolId = 0
	tmpId = -1
	if request.cookies.has_key('global.school.id') : tmpId = request.cookies['global.school.id']
	for i in range(0, len(c.schools)) :
		s = c.schools[i]
		if tmpId == str(s.id) : curSchoolId = i
%>
<div class="global_header"><div id="global_header_mid">
	<script type="text/javascript">
		$(document).ready(function(){
			var schoolMenu = $("#global_panel #school_menu");
			var loginMenu = $("#global_panel #login_menu");
			var notifyMenu = $("#global_panel #notification_menu");
			$("#global_panel #school").click(function(){
				schoolMenu.removeClass("menu");
				schoolMenu.addClass("menu_show");
				schoolMenu.css("left", $("#global_panel #school").width() - schoolMenu.width() + 8 + "px");
				$("#global_panel #school").removeClass("head_normal");
				$("#global_panel #school").addClass("head_activated");
			});
			$("#global_panel #login").click(function(){
				loginMenu.removeClass("menu");
				loginMenu.addClass("menu_show");
				loginMenu.css("left", $("#global_panel #login").width() - loginMenu.width() + 8 + "px");
				$("#global_panel #login").removeClass("head_normal");
				$("#global_panel #login").addClass("head_activated");
			});
			$("#global_panel #notification").click(function(){
				notifyMenu.removeClass("menu");
				notifyMenu.addClass("menu_show");
				notifyMenu.css("left", $("#global_panel #notification").width() - notifyMenu.width() + 8 + "px");
				$("#global_panel #notification").removeClass("head_normal");
				$("#global_panel #notification").addClass("head_activated");
			});
			$(document).click(function(event){
				if (!$(event.target).closest("#global_panel #school_menu").size() && !$(event.target).closest("#global_panel #school").size()){
					schoolMenu.addClass("menu");
					schoolMenu.removeClass("menu_show");
					$("#global_panel #school").addClass("head_normal");
					$("#global_panel #school").removeClass("head_activated");
				}
				if (!$(event.target).closest("#global_panel #login_menu").size() && !$(event.target).closest("#global_panel #login").size()){
					loginMenu.addClass("menu");
					loginMenu.removeClass("menu_show");
					$("#global_panel #login").addClass("head_normal");
					$("#global_panel #login").removeClass("head_activated");
				}
				if (!$(event.target).closest("#global_panel #notification_menu").size() && !$(event.target).closest("#global_panel #notification").size()){
					notifyMenu.addClass("menu");
					notifyMenu.removeClass("menu_show");
					$("#global_panel #notification").addClass("head_normal");
					$("#global_panel #notification").removeClass("head_activated");
				}
			});
		});
	</script>
	<div id="fidologo"><a href="/map"></a></div>
	<div id="globalnav">
		% if url.current()[ : 4] == '/map' or url.current()[ : 18] == '/dispatch.fcgi/map':
		<li><a id="link_places_cur"></a></li>
		% else :
		<li><a id="link_places" href="/map"></a></li>
		% endif
		% if url.current()[ : 6] == '/login' or url.current()[ : 20] == '/dispatch.fcgi/login':
			<li><a id="link_myfido_cur"></a></li>
		% else :
			<li><a id="link_myfido" href="/login"></a></li>
		% endif
	</div>
	<div id="globalpanel">
		<div id="global_panel">
			<div style="float:left;position:relative;">
				<div id="school_menu" class="menu">
					<h2>请选择学校...</h2>
					<div style="border-bottom:1px solid #CCCCCC;margin:3px 0;"></div>
					<ul>
						% for s in c.schools :
							<li><a href="javascript:globalCtrl.setCurSchool(${s.id});">${s.name}</a></li>
						% endfor
					</ul>
				</div>
				<div id="school" class="head_normal">
					<span id="school_icon"></span>
					<span id="cur_school">${c.schools[curSchoolId].name}</span>
					<span id="global_menu_dropdown"></span>
				</div>
			</div>
			% if c.loginUser != None :
				<div style="float:left;position:relative;">
					<div id="notification_menu" class="menu">
						<h2>消息</h2>
						<div style="border-bottom:1px solid #CCCCCC;margin:3px 0;"></div>
						<ul>
							<%
								notifyCount = 0
							%>
							% for n in c.loginUser.notifications :
								<% notifyCount += 1 %>
								<li><div id="update_time">${n.updateTime.strftime('%m-%d %H:%M')}</div><div id="content">${n.content}</div></li>
							% endfor
							% if notifyCount == 0 : 
								暂无新消息
							% endif
						</ul>
					</div>
					<div id="notification" class="head_normal">
						<span id="head">	
							<span id="notification_icon"></span>
							<span id="notification_count">${notifyCount}条消息</span>
							<span id="global_menu_dropdown"></span>
						</span>
					</div>
				</div>
				<div style="float:left;position:relative;">
					<div id="login_menu" class="menu">
						<div style="clear:both;"><a href="/login/index/settings">设置</a></div>
						<div style="clear:both;"><a href="javascript:globalCtrl.logout();">登出</a></div>
					</div>
					<div id="login" class="head_normal">
						<span id="head">	
							<span id="user_icon"></span>
							<span id="global_menu_user_name">${c.loginUser.name}</span>
							<span id="global_menu_dropdown"></span>
						</span>
					</div>
				</div>
			% else :
				<div id="dv_login"><span id="login_icon"></span><a href="/login">登录</a></div>
				<div id="dv_signup"><span id="signup_icon"></span><a href="/login/signup">注册</a></div>
			% endif
		</div>
</div></div>

